package com.cskt.service;

import com.cskt.dao.StudentMapper;
import com.cskt.entity.Student;
import com.cskt.util.Pager;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * Created by bb on 2018/3/12.
 * 学生的业务层实现类
 */
@Service
public class StudentServiceImpl implements StudentService{
    @Autowired
    private StudentMapper studentMapper;

    /**
     * 分页的sql
     *
     * @param pager
     */
    @Override
    public List<Student> getByPagers(Pager pager) {
        //拿到总记录数
        pager.setToatPages(studentMapper.getCounts());
        Map<String,Object> mpa=new HashMap<>();
        mpa.put("pageIndex",(pager.getCurrPage()-1)*pager.getPageSize());
        mpa.put("pageSize",pager.getPageSize());
        List<Student> list=studentMapper.getByPagers(mpa);
        return list;
    }

    @Override
    public List<Student> getAllStudent() {
        return studentMapper.getAllStudent();
    }

    @Override
    public int studentDelet(Integer sid) {
        return studentMapper.studentDelet(sid);
    }

    @Override
    public int updateStudent(Student student) {
        return studentMapper.updateStudent(student);
    }

    @Override
    public Student studentId(Integer map) {
        return studentMapper.studentId(map);
    }


    @Override
    public int addStudnet(Student student) {
        return studentMapper.addStudnet(student);
    }
}
